package com.fh.controller.building.park;


import com.fh.controller.base.BaseController;
import com.fh.controller.system.tools.PushToApp;
import com.fh.entity.Page;
import com.fh.entity.system.User;
import com.fh.service.attachment.AttachmentService;
import com.fh.service.building.RecordService;
import com.fh.service.building.bill.BillService;
import com.fh.service.building.contract.ContractService;
import com.fh.service.building.park.ParkService;
import com.fh.service.property.PropertyService;
import com.fh.service.role.ShsRoleService;
import com.fh.service.system.user.UserService;
import com.fh.util.*;
import net.sf.json.JSONArray;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.*;

import static com.fh.controller.system.tools.GetDatalayui.getLData;
import static com.fh.controller.system.tools.GetDatalayui.getPData;

/**
 * ch
 */
@Controller
@RequestMapping(value = "/parkController")
public class ParkController extends BaseController{
    @Resource(name = "parkService")
    private ParkService parkService;


    @RequestMapping(value = "/save")
    @ResponseBody
    public PageData save() {
        PageData pageData = this.getPageData();
        PageData res = new PageData();

        //获取当前登录用户
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        User user = (User) session.getAttribute(Const.SESSION_USER);
        try {
            pageData.put("ID",this.get32UUID());
            pageData.put("CREATE_ID",user.getUSER_ID());
            pageData.put("CREATE_DATE",new DateUtil().getTime());
            pageData.put("UPDATE_ID",user.getUSER_ID());
            pageData.put("UPDATE_DATE",new DateUtil().getTime());
            pageData.put("SORT",'0');
            pageData.put("IS_DEL",'0');
            pageData.put("PARK_NAME","测试5");
            pageData.put("BUILDING_ID","c154ff7961d84363b00ec5769b438b40");
            parkService.save(pageData);
            res.put("data", "");
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }



        return res;
    }



    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(Page page) {
        PageData pd = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList=new ArrayList<>();
        String datalayui = null;
        try {
            pd = this.getPageData();
            getPData(page, pd);
            varList = parkService.list(page);
            datalayui = getLData(page, varList);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        } finally {
            logAfter(logger);
        }
        return varList;
    }


    @RequestMapping(value = "/findlist")
    @ResponseBody
    public PageData findlist() {
        PageData res = new PageData();
        Map<String, Object> map = new HashMap<String, Object>();
        List<PageData> varList=new ArrayList<>();
        try {
            PageData pd = this.getPageData();
            varList = parkService.findlist(pd);
            res.put("data",varList);
            res.put("errcode", "0");
            res.put("errmsg", "ok");
        } catch (Exception e) {
            logger.error(e.toString(), e);
            res.put("data", "");
            res.put("errcode", "1");
            res.put("errmsg", e.toString());
        }

        return res;
    }

}





